package guan.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import guan.shop.entity.Product;
import guan.shop.entity.Response;
import guan.shop.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping("/findSwiper")
    public Response findSwiper(){
        List<Product> swiperList = productService.list(
                new QueryWrapper<Product>()
                        .eq("isSwiper", true)
                        .orderByAsc("swiperSort")
        );
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("message", swiperList);
        return Response.ok(hashMap);
    }

    @GetMapping("/findHot")
    public Response findHot(){
        Page<Product> page = new Page<>(0, 8);
        Page<Product> pageProduct = productService.page(page, new QueryWrapper<Product>().eq("isHot", true).orderByAsc("hotDateTime"));
        List<Product> records = pageProduct.getRecords();
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("message", records);
        return Response.ok(hashMap);
    }
}
